<?php
//模型
class UserModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'user';
		
		$this->lists = array();
	}
	
	function get_list($arr,$page=1,$size=10){
		$where = ' 1 ';
		
		if(isset($arr['username']) && !empty($arr['username'])){
			$where .= " AND username like '%{$arr['username']}%'";
		}
		if(isset($arr['name']) && !empty($arr['name'])){
			$where .= " AND (nickname like '%{$arr['name']}%' OR en_name like '%{$arr['name']}%') ";
		}
		if(isset($arr['reg_time']) && !empty($arr['reg_time'])){
			$date = date('Y-m-d',strtotime($arr['reg_time']));
			$where .= " AND FROM_UNIXTIME(ADDTIME,'%Y-%m-%d') ='{$date}'";
		}
		if(isset($arr['company']) && !empty($arr['company'])){
			$where .= " AND company = '{$arr['company']}'";
		}
		if(isset($arr['region']) && !empty($arr['region'])){
			$where .= " AND region = '{$arr['region']}'";
		}
		if(isset($arr['bumen']) && !empty($arr['bumen'])){
			$where .= " AND bumen LIKE '%{$arr['bumen']}%'";
		}
		
		
		$res = $this->_where_get_list($where,$page,$size);
		return $res;
	}
	
	function get_info($id){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where id='{$id}' limit 1";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return $row;
	}
	
	function ids_get_list($ids){
		if(is_array($ids)){
			$ids = implode(',',$ids);
		}
		if(empty($ids)){
			return false;
		}
		$sql  = "select id,nickname,addtime,mobile from ".$this->db->dbprefix.$this->table." where id in({$ids})";
		$query = $this->db->query($sql);
		$res = $query->result_array();
		return $res;
	}
	
	function get_user($id){
		if(isset($this->lists[$id])){
			return $this->lists[$id];
		}
		
		$info = $this->get_info($id);
		$this->lists[$id] = $info;
		
		
		return $info;
	}
	
}

